// 
// Decompiled by Procyon v0.5.36
// 

package com.cyberfend.cyfsecurity;

import java.util.*;
import android.app.*;
import com.cyberfend.cyfsecurity.b.*;
import android.os.*;
import android.hardware.*;

final class j extends java.util.Observable implements android.hardware.SensorEventListener
{
    private android.hardware.SensorManager b;
    private android.hardware.Sensor c;
    private android.hardware.Sensor d;
    private long e;
    private boolean f;
    private boolean g;
    private boolean h;
    private boolean i;
    boolean a;
    private float j;
    private float k;
    private float l;
    private float m;
    private float n;
    private float o;
    private float p;
    private float q;
    private float r;
    private float s;
    private final float[] t;
    private int u;
    
    public j(final android.app.Application application) {
        this.e = 0L;
        this.f = false;
        this.g = false;
        this.h = false;
        this.i = false;
        this.a = false;
        this.j = -1.0f;
        this.k = -1.0f;
        this.l = -1.0f;
        this.m = -1.0f;
        this.n = -1.0f;
        this.o = -1.0f;
        this.p = -1.0f;
        this.q = -1.0f;
        this.r = -1.0f;
        this.s = 0.0f;
        this.t = new float[] { 0.0f, 0.0f, 0.0f };
        this.u = 0;
        try {
            this.b = (android.hardware.SensorManager)application.getSystemService("sensor");
        }
        catch (java.lang.Exception ex) {
            com.cyberfend.cyfsecurity.b.a.c("MotionListener", "Exception on getting sensor service", ex);
            com.cyberfend.cyfsecurity.f.a(ex);
        }
    }
    
    final boolean a() throws java.lang.Exception {
        final java.lang.Throwable[] array = new java.lang.Throwable[0];
        this.c = this.b.getDefaultSensor(1);
        this.d = this.b.getDefaultSensor(4);
        this.f = this.b.registerListener((android.hardware.SensorEventListener)this, this.c, 3);
        this.g = this.b.registerListener((android.hardware.SensorEventListener)this, this.d, 3);
        com.cyberfend.cyfsecurity.b.a.a("MotionListener", "GyroScope status " + this.g + " and Accelerometer status " + this.f, new java.lang.Throwable[0]);
        if (!this.f && !this.g) {
            com.cyberfend.cyfsecurity.b.a.c("MotionListener", "Failed to register motion listener", new java.lang.Throwable[0]);
            this.b();
            return false;
        }
        this.i = !this.f;
        this.h = !this.g;
        this.e = android.os.SystemClock.uptimeMillis();
        this.s = (float)java.lang.System.nanoTime();
        this.u = 0;
        return true;
    }
    
    public final void b() throws java.lang.Exception {
        new java.lang.StringBuilder("Unregister Gyroscope ").append(this.g).append(" and Accelerometer ").append(this.f);
        final java.lang.Throwable[] array = new java.lang.Throwable[0];
        if (this.g) {
            this.b.unregisterListener((android.hardware.SensorEventListener)this, this.d);
            this.g = false;
        }
        if (this.f) {
            this.b.unregisterListener((android.hardware.SensorEventListener)this, this.c);
            this.f = false;
        }
        this.a = false;
    }
    
    public final void onAccuracyChanged(final android.hardware.Sensor sensor, final int accuracy) {
    }
    
    public final void onSensorChanged(final android.hardware.SensorEvent event) {
        try {
            final long uptimeMillis = android.os.SystemClock.uptimeMillis();
            if (!this.a && event.accuracy == 0) {
                com.cyberfend.cyfsecurity.b.a.b("MotionListener", "Unreliable motion sensors data...", new java.lang.Throwable[0]);
                this.a = true;
            }
            final int type = event.sensor.getType();
            new java.lang.StringBuilder("Motion sensor changed elapsed time: ").append(uptimeMillis - this.e).append(", Sensor Type: ").append(type);
            final java.lang.Throwable[] array = new java.lang.Throwable[0];
            if (type == 4) {
                if (this.g) {
                    this.p = event.values[0];
                    this.q = event.values[1];
                    this.r = event.values[2];
                    this.h = true;
                }
            }
            else if (type == 1 && this.f) {
                this.j = event.values[0];
                this.k = event.values[1];
                this.l = event.values[2];
                final float[] values = event.values;
                float n;
                if (java.lang.Float.isNaN(n = 1.0f / (++this.u / ((java.lang.System.nanoTime() - this.s) / 1.0E9f))) || java.lang.Float.isInfinite(n)) {
                    n = 0.0f;
                }
                final float n2 = 0.18f / (0.18f + n);
                this.t[0] = n2 * this.t[0] + (1.0f - n2) * values[0];
                this.t[1] = n2 * this.t[1] + (1.0f - n2) * values[1];
                this.t[2] = n2 * this.t[2] + (1.0f - n2) * values[2];
                final float[] array3;
                final float[] array2 = array3 = new float[] { 0.0f, 0.0f, 0.0f };
                array2[0] = values[0] - this.t[0];
                array3[1] = values[1] - this.t[1];
                array3[2] = values[2] - this.t[2];
                if (java.lang.Float.isNaN(array3[0]) || java.lang.Float.isInfinite(array3[0])) {
                    array3[0] = 0.0f;
                }
                if (java.lang.Float.isNaN(array3[1]) || java.lang.Float.isInfinite(array3[1])) {
                    array3[1] = 0.0f;
                }
                if (java.lang.Float.isNaN(array3[2]) || java.lang.Float.isInfinite(array3[2])) {
                    array3[2] = 0.0f;
                }
                final float[] array4 = array3;
                this.m = array4[0];
                this.n = array4[1];
                this.o = array4[2];
                this.j *= -1.0f;
                this.k *= -1.0f;
                this.l *= -1.0f;
                this.m *= -1.0f;
                this.n *= -1.0f;
                this.o *= -1.0f;
                this.i = true;
            }
            if (this.h && this.i && (uptimeMillis - this.e >= 100L || com.cyberfend.cyfsecurity.d.l == 1)) {
                new java.lang.StringBuilder("Motion event elapsed time: ").append(uptimeMillis - this.e);
                final java.lang.Throwable[] array5 = new java.lang.Throwable[0];
                this.e = uptimeMillis;
                final boolean b = com.cyberfend.cyfsecurity.d.l != 0;
                com.cyberfend.cyfsecurity.d.l = 0;
                this.setChanged();
                new java.lang.StringBuilder("Data: ax:").append(this.j).append(", ay:").append(this.k).append(", az:").append(this.l).append("; agx:").append(this.m).append(", agy:").append(this.n).append(", agz:").append(this.o).append("; gx:").append(this.p).append(", gy:").append(this.q).append(", gz:").append(this.r);
                final java.lang.Throwable[] array6 = new java.lang.Throwable[0];
                this.notifyObservers(new com.cyberfend.cyfsecurity.l(this.j, this.k, this.l, this.m, this.n, this.o, this.p, this.q, this.r, this.e, b ? 2 : 1));
                this.h = !this.g;
                this.i = !this.f;
            }
        }
        catch (java.lang.Exception ex) {
            com.cyberfend.cyfsecurity.b.a.b("MotionListener", "Exception in processing motion event", ex);
            com.cyberfend.cyfsecurity.f.a(ex);
        }
    }
}
